Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Control table</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Control_table"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.math.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Control_table rootpage-Control_table skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Control table</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1251242444">
/* start https://en.wikipedia.org/ */


.mw-parser-output .ambox{border:1px solid #a2a9b1;border-left:10px solid #36c;background-color:#fbfbfb;box-sizing:border-box}.mw-parser-output .ambox+link+.ambox,.mw-parser-output .ambox+link+style+.ambox,.mw-parser-output .ambox+link+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+style+.ambox,.mw-parser-output .ambox+.mw-empty-elt+link+link+.ambox{margin-top:-1px}html body.mediawiki .mw-parser-output .ambox.mbox-small-left{margin:4px 1em 4px 0;overflow:hidden;width:238px;border-collapse:collapse;font-size:88%;line-height:1.25em}.mw-parser-output .ambox-speedy{border-left:10px solid #b32424;background-color:#fee7e6}.mw-parser-output .ambox-delete{border-left:10px solid #b32424}.mw-parser-output .ambox-content{border-left:10px solid #f28500}.mw-parser-output .ambox-style{border-left:10px solid #fc3}.mw-parser-output .ambox-move{border-left:10px solid #9932cc}.mw-parser-output .ambox-protection{border-left:10px solid #a2a9b1}.mw-parser-output .ambox .mbox-text{border:none;padding:0.25em 0.5em;width:100%}.mw-parser-output .ambox .mbox-image{border:none;padding:2px 0 2px 0.5em;text-align:center}.mw-parser-output .ambox .mbox-imageright{border:none;padding:2px 0.5em 2px 0;text-align:center}.mw-parser-output .ambox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ambox .mbox-image-div{width:52px}@media(min-width:720px){.mw-parser-output .ambox{margin:0 10%}}@media print{body.ns-0 .mw-parser-output .ambox{display:none!important}}


/* end https://en.wikipedia.org/ */
</style>

<p>A <b>control table</b> is a <a href="Array_(data_structure)" title="Array (data structure)">array</a> of <a href="Record_(computer_science)" title="Record (computer science)">records</a> used to direct the <a href="Control_flow" title="Control flow">control flow</a> of a <a href="Computer_program" title="Computer program">computer program</a>. <a href="Software" title="Software">Software</a> that uses a control table is said to be <i>table-driven</i>.<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> A control table encodes both a <a href="Conditional_(programming)" class="mw-redirect" title="Conditional (programming)">conditional expression</a> and a <a href="Function_(computer_programming)" title="Function (computer programming)">function</a> <a href="Reference_(computer_science)" title="Reference (computer science)">reference</a>. An <a href="Interpreter_(computing)" title="Interpreter (computing)">interpreter</a> processes a table by applying input data to the conditional expression and invoking the selected function. Using a control table can reduce the need for repetitive code that implements the same logic. The two-dimensional nature of most tables makes them easier to view and update than the one-dimensional nature of program code.
</p><p>Typical uses for a control table include:
</p>
<ul><li>Transform an input value to an <a href="Associative_array" title="Associative array">index</a>, for branching or <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> <a href="Lookup_table" title="Lookup table">lookup</a></li>
<li>Transform an input value to a program name, relative <a href="Subroutine" class="mw-redirect" title="Subroutine">subroutine</a> number, <a href="Label_(programming_language)" class="mw-redirect" title="Label (programming language)">program label</a> or program <a href="Offset_(computer_science)" title="Offset (computer science)">offset</a>, to alter <a href="Control_flow" title="Control flow">control flow</a></li>
<li>Control a <a href="Main_loop" class="mw-redirect" title="Main loop">main loop</a> in <a href="Event-driven_programming" title="Event-driven programming">event-driven programming</a> using a <a href="Control_variable_(programming)" class="mw-redirect" title="Control variable (programming)">control variable</a> for <a href="State_transition" class="mw-redirect" title="State transition">state transitions</a></li>
<li>Control the program cycle for <a href="Online_transaction_processing" title="Online transaction processing">online transaction processing</a> applications</li></ul>
<p>A relatively advanced use as instructions for a <a href="Virtual_machine" title="Virtual machine">virtual machine</a> processed by an interpreter – similar to <a href="Bytecode" title="Bytecode">bytecode</a> but usually with operations implied by the table structure itself.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Data_structure">Data structure</h2></div>
<p>A table can be structured in a variety of ways. It may have one or multiple dimensions and be of fixed or <a href="Variable_length_code" class="mw-redirect" title="Variable length code">variable length</a>. The structure of the table may be similar to a <a href="Multimap_(data_structure)" class="mw-redirect" title="Multimap (data structure)">multimap</a> <a href="Associative_array" title="Associative array">associative array</a>, where a data value (or combination of data values) may be mapped to one or more functions to be performed. Often, the structure allows tabular data is <a href="Software_portability" title="Software portability">portable</a> between <a href="Computer_platform" class="mw-redirect" title="Computer platform">computer platforms</a> as long as a compatible interpreter exists on each platform.
</p>
<div class="mw-heading mw-heading3"><h3 id="Trival_hash_function">Trival hash function</h3></div>
<p>A relatively simple implementation consists of a <a href="Sparse_file" title="Sparse file">sparse</a>, one-dimensional array of values. The index space is fully covered by the array such that lookup involves indexing into the array by the input value, and a value is found even for an index that is not intended to be used; preventing an error that might otherwise occur for an unused index value. The lookup is achieved in <a href="Constant_time" class="mw-redirect" title="Constant time">constant time</a>; without searching. In most <a href="Computer_architecture" title="Computer architecture">architectures</a>, this can be accomplished in two or three <a href="Machine_instruction" class="mw-redirect" title="Machine instruction">machine instructions</a>. The technique is known as a "<a href="Trivial_hash_function" class="mw-redirect" title="Trivial hash function">trivial hash function</a>" or, when used specifically for branch tables, "<a href="Double_dispatch" title="Double dispatch">double dispatch</a>".
</p><p>To be feasible, the range of index values should be relatively small. In the example below, the control table is indexed by ASCII value so it has 256 entries; an entry for each ASCII value; omitted entries are shown as '...'. Only the values for the letter A, D, M, and S are important. All other values are uninteresting and set to 0. A two-byte index would require a minimum of 65,536 entries to handle all input possibilities.
</p>
<table class="wikitable" style="text-align:center;">
<caption>
</caption>
<tbody><tr style="vertical-align:bottom;">
<th>index<br>(ASCII)</th>
<th>Array
</th></tr>
<tr>
<td>0</td>
<td style="background:lightblue;">0
</td></tr>
<tr>
<td>...</td>
<td style="background:lightblue;">0
</td></tr>
<tr>
<td>65 (A)</td>
<td style="background:lightblue;">1
</td></tr>
<tr>
<td>...</td>
<td style="background:lightblue;">0
</td></tr>
<tr>
<td>68 (D)</td>
<td style="background:lightblue;">4
</td></tr>
<tr>
<td>...</td>
<td style="background:lightblue;">0
</td></tr>
<tr>
<td>77 (M)</td>
<td style="background:lightblue;">3
</td></tr>
<tr>
<td>...</td>
<td style="background:lightblue;">0
</td></tr>
<tr>
<td>83 (S)</td>
<td style="background:lightblue;">2
</td></tr>
<tr>
<td>...</td>
<td style="background:lightblue;">0
</td></tr>
<tr>
<td>255</td>
<td style="background:lightblue;">0
</td></tr></tbody></table>
<p>In automata-based programming and <a href="Pseudoconversational_transaction" title="Pseudoconversational transaction">pseudoconversational transaction</a> processing, if the number of distinct program states is small, a "dense sequence" control variable can be used to efficiently dictate the entire flow of the main program loop.
</p>
<div class="mw-heading mw-heading3"><h3 id="Branch_table">Branch table</h3></div>
<p>A <a href="Branch_table" title="Branch table">branch table</a> is a one-dimensional array of <a href="Machine_code" title="Machine code">machine code</a> <a href="Branch_(computer_science)" title="Branch (computer science)">branch/jump</a> instructions to effect a <a href="Multiway_branch" title="Multiway branch">multiway branch</a> to a program label when branched into by an immediately preceding, and indexed branch. It is sometimes generated by an <a href="Optimizing_compiler" title="Optimizing compiler">optimizing compiler</a> to execute a <a href="Switch_statement" title="Switch statement">switch statement</a> – provided that the input range is small and dense, with few gaps.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> (as created by the previous array example)
</p><p>Although quite compact – compared to the multiple equivalent <code>If</code> statements – the branch instructions still carry some redundancy, since the branch <a href="Opcode" title="Opcode">opcode</a> and condition code mask are repeated alongside the branch offsets. Control tables containing only the offsets to the program labels can be constructed to overcome this redundancy (at least in assembly languages) and yet requiring only minor execution time <a href="Computational_overhead" class="mw-redirect" title="Computational overhead">overhead</a> compared to a conventional branch table.
</p>
<div class="mw-heading mw-heading3"><h3 id="Decision_table">Decision table</h3></div>
<p>Often, a control table is a <a href="Truth_table" title="Truth table">truth table</a> or an implementation of a <a href="Decision_table" title="Decision table">decision table</a> or a <a href="Tree_(data_structure)" class="mw-redirect" title="Tree (data structure)">tree</a> of decision tables. The tables contains (often implied) <a href="Propositional_formula" title="Propositional formula">propositions</a>, together with one or more associated actions. The actions are usually performed by generic or custom-built <a href="Subroutine" class="mw-redirect" title="Subroutine">subroutines</a> that are called by an interpreter. The interpreter, a <a href="Virtual_machine" title="Virtual machine">virtual machine</a>, executes the control table entries and thus provides a higher level of <a href="Abstraction_(computer_science)" title="Abstraction (computer science)">abstraction</a> than the interpreter.
</p><p>A control table can act like a <a href="Switch_statement" title="Switch statement">switch statement</a> or more generally as a nested <a href="If-then-else" class="mw-redirect" title="If-then-else">if-then-else</a> construct that includes <a href="Logical_predicate" class="mw-redirect" title="Logical predicate">logical predicates</a> (using <a href="Boolean_algebra_(logic)" class="mw-redirect" title="Boolean algebra (logic)">boolean</a> style <a href="Logical_conjunction" title="Logical conjunction">AND</a>/<a href="Logical_disjunction" title="Logical disjunction">OR</a> conditions) for each case. Such as control table provides for a language-independent implementation of what otherwise is a language-dependent construct. The table embodies the <a href="Essence" title="Essence">essence</a> of a program; stripped of programming language syntax and platform dependent aspects; condensed to data and implied logic. The meaning of the table includes implied operations instead of being explicit as in a more typical a <a href="Programming_paradigm" title="Programming paradigm">programming paradigm</a>.
</p><p>Typically, a two-dimensional control table contains value/action pairs and may additionally contain operators and <a href="Type_system" title="Type system">type</a> information such as the location, size and format of input or output data, whether <a href="Data_conversion" title="Data conversion">data conversion</a> is required. The table may contain <a href="Array_index" class="mw-redirect" title="Array index">indexes</a> or relative or absolute <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointers</a> to generic or customized primitives or <a href="Subroutine" class="mw-redirect" title="Subroutine">subroutines</a> to be executed depending upon other values in the row.
</p><p>The table below is a prototype of a control table that implies an action based on a single input value.
</p>
<table class="wikitable">
<caption>
</caption>
<tbody><tr>
<th>(implied) IF =</th>
<th>(implied) perform
</th></tr>
<tr>
<td>value</td>
<td>action
</td></tr>
<tr>
<td>value</td>
<td>action
</td></tr></tbody></table>
<p>The type of values used to in a control table depends on the <a href="Computer_language" title="Computer language">computer language</a> used for the interpreter. <a href="Assembly_language" title="Assembly language">Assembly language</a> provides the widest scope for <a href="Data_types" class="mw-redirect" title="Data types">data types</a> including <a href="Machine_code" title="Machine code">machine code</a> for lookup values. Typically, a control table contains values for each possible matching class of input together with a corresponding pointer to an action subroutine. For a language without <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> support, the table can encode an index which can imply an offset value that can be used to accomplish the same as a pointer.
</p>
<div class="mw-heading mw-heading2"><h2 id="Storage">Storage</h2></div>
<p>A control table can be stored a variety of ways. It can be stored as part of a program; for example as a <a href="Static_variable" title="Static variable">static variable</a>. It can stored in the <a href="File_system" title="File system">file system</a>; for example as <a href="Flat_file" class="mw-redirect" title="Flat file">flat file</a> or in a <a href="Database" title="Database">database</a>. It can be built dynamically by the program. For efficiency, the table should be resident in program memory when the interpreter uses it.
</p>
<div class="mw-heading mw-heading2"><h2 id="The_interpreter_and_subroutines">The interpreter and subroutines</h2></div>
<p>The interpreter can be written in any suitable programming language including a <a href="High_level_language" class="mw-redirect" title="High level language">high level language</a>. A suitably designed <a href="Generic_programming" title="Generic programming">generic</a> interpreter, together with a well chosen set of generic subroutines (able to process the most commonly occurring primitives), would require additional conventional coding only for new custom subroutines (in addition to specifying the control table itself). The interpreter, optionally, may only apply to some well-defined sections of a complete application program (such as the <a href="Main_loop" class="mw-redirect" title="Main loop">main control loop</a>) and not other, 'less conditional', sections (such as program initialization, termination and so on).
</p><p>The interpreter does not need to be unduly complex, or produced by a programmer with the advanced knowledge of a compiler writer, and can be written just as any other application program – except that it is usually designed with efficiency in mind. Its primary function is to "execute" the table entries as a set of "instructions". There need be no requirement for parsing of control table entries and these should therefore be designed, as far as possible, to be 'execution ready', requiring only the "plugging in" of variables from the appropriate columns to the already compiled generic code of the interpreter. The <a href="Instruction_(computer_science)" class="mw-redirect" title="Instruction (computer science)">program instructions</a> are, in theory, infinitely <a href="Extensible" class="mw-redirect" title="Extensible">extensible</a> and constitute (possibly arbitrary) values within the table that are meaningful only to the interpreter. The <a href="Control_flow" title="Control flow">control flow</a> of the interpreter is normally by sequential processing of each table row but may be modified by specific actions in the table entries.
</p><p>These arbitrary values can thus be designed with <a href="Algorithmic_efficiency" title="Algorithmic efficiency">efficiency</a> in mind – by selecting values that can be used as direct indexes to data or <a href="Function_pointers" class="mw-redirect" title="Function pointers">function pointers</a>. For particular platforms/<a href="Computer_language" title="Computer language">language</a>, they can be specifically designed to minimize <a href="Instruction_path_length" title="Instruction path length">instruction path lengths</a> using <a href="Branch_table" title="Branch table">branch table</a> values or even, in some cases such as in <a href="Just-in-time_compilation" title="Just-in-time compilation">JIT</a> compilers, consist of directly executable <a href="Machine_code" title="Machine code">machine code</a> "<a href="Snippet_(programming)" title="Snippet (programming)">snippets</a>" (or pointers to them).
</p><p>The subroutines may be coded either in the same language as the interpreter itself or any other supported program language (provided that suitable inter-language 'Call' linkage mechanisms exist). The choice of language for the interpreter and/or subroutines will usually depend upon how portable it needs to be across various <a href="Platform_(computing)" class="mw-redirect" title="Platform (computing)">platforms</a>. There may be several versions of the interpreter to enhance the <a href="Porting" title="Porting">portability</a> of a control table. A subordinate control table pointer may optionally substitute for a subroutine pointer in the 'action' columns if the interpreter supports this construct, representing a conditional 'drop' to a lower logical level, mimicking a conventional <a href="Structured_programming" title="Structured programming">structured program</a> structure.
</p>
<div class="mw-heading mw-heading2"><h2 id="Performance_considerations">Performance considerations</h2></div>
<p>At first sight, the use of control tables would appear to add quite a lot to a program's <a href="Computational_overhead" class="mw-redirect" title="Computational overhead">overhead</a>, requiring, as it does, an interpreter process before the 'native' programming language statements are executed. This however is not always the case. By separating (or 'encapsulating') the executable coding from the logic, as expressed in the table, it can be more readily targeted to perform its function most efficiently. This may be experienced most obviously in a <a href="Spreadsheet" title="Spreadsheet">spreadsheet</a> application – where the underlying spreadsheet software transparently converts complex logical 'formulae' in the most efficient manner it is able, in order to display its results.
</p><p>The examples below have been chosen partly to illustrate potential performance gains that may not only <i>compensate</i> significantly for the additional tier of abstraction, but also <i>improve</i> upon – what otherwise might have been – less efficient, less maintainable and lengthier code. Although the examples given are for a 'low level' assembly language and for the <a href="C_(language)" class="mw-redirect" title="C (language)">C language</a>, it can be seen, in both cases, that very few lines of code are required to implement the control table approach and yet can achieve very significant <a href="Constant_time" class="mw-redirect" title="Constant time">constant time</a> performance improvements, reduce repetitive source coding and aid clarity, as compared with <a href="Verbose" class="mw-redirect" title="Verbose">verbose</a> conventional program language constructs. See also the <a class="mw-selflink-fragment" href="#Quotations">quotations</a> by <a href="Donald_Knuth" title="Donald Knuth">Donald Knuth</a>, concerning tables and the efficiency of <a href="Multiway_branch" title="Multiway branch">multiway branching</a> in this article.
</p>
<div class="mw-heading mw-heading2"><h2 id="Examples_of_control_tables">Examples of control tables</h2></div>
<p>The following examples are <a href="Arbitrary" class="mw-redirect" title="Arbitrary">arbitrary</a> (and based upon just a single input for simplicity), however the intention is merely to demonstrate how control flow can be effected via the use of tables instead of regular program statements. It should be clear that this technique can easily be extended to deal with multiple inputs, either by increasing the number of columns or utilizing multiple table entries (with optional and/or operator). Similarly, by using (hierarchical) 'linked' control tables, <a href="Structured_programming" title="Structured programming">structured programming</a> can be accomplished (optionally using indentation to help highlight subordinate control tables).
</p><p>"CT1" is an example of a control table that is a simple <a href="Lookup_table" title="Lookup table">lookup table</a>. The first column represents the input value to be tested (by an implied 'IF input1 = x') and, if TRUE, the corresponding 2nd column (the 'action') contains a subroutine address to perform by a <a href="System_call" title="System call">call</a> (or <a href="Goto" title="Goto">jump</a> to – similar to a <a href="Switch_statement" title="Switch statement">SWITCH</a> statement). It is, in effect, a <a href="Multiway_branch" title="Multiway branch">multiway branch</a> with return (a form of "<a href="Dynamic_dispatch" title="Dynamic dispatch">dynamic dispatch</a>"). The last entry is the default case where no match is found.
</p>
<dl><dd><table class="wikitable">
<caption>CT1
</caption>
<tbody><tr>
<th>input 1</th>
<th></th>
<th><a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a>
</th></tr>
<tr>
<td><style data-mw-deduplicate="TemplateStyles:r886049734">
/* start https://en.wikipedia.org/ */


.mw-parser-output .monospaced{font-family:monospace,monospace}


/* end https://en.wikipedia.org/ */
</style><span class="monospaced">A</span></td>
<td>→</td>
<td>Add
</td></tr>
<tr>
<td><span class="monospaced">S</span></td>
<td>→</td>
<td>Subtract
</td></tr>
<tr>
<td><span class="monospaced">M</span></td>
<td>→</td>
<td>Multiply
</td></tr>
<tr>
<td><span class="monospaced">D</span></td>
<td>→</td>
<td>Divide
</td></tr>
<tr>
<td><span class="monospaced">?</span></td>
<td>→</td>
<td>Default
</td></tr></tbody></table></dd></dl>
<p>For programming languages that support pointers within <a href="Data_structure" title="Data structure">data structures</a> alongside other data values, the above table (CT1) can be used to direct <a href="Control_flow" title="Control flow">control flow</a> to an appropriate <a href="Subroutine" class="mw-redirect" title="Subroutine">subroutines</a> according to matching value from the table (without a column to indicate otherwise, equality is assumed in this simple case).
</p>
<div class="mw-heading mw-heading3"><h3 id="Assembly_language">Assembly language</h3></div>
<p>No attempt is made to optimize the lookup in coding for this first example (for <a href="IBM/360" class="mw-redirect" title="IBM/360">IBM/360</a> maximum 16Mb address range or <a href="Z/Architecture" title="Z/Architecture">Z/Architecture</a>), and it uses instead a simple <a href="Linear_search" title="Linear search">linear search</a> technique – purely to illustrate the concept and demonstrate fewer source lines. To handle all 256 different input values, approximately 265 lines of source code would be required (mainly single line table entries) whereas multiple 'compare and branch' would have normally required around 512 source lines (the size of the <a href="Binary_file" title="Binary file">binary</a> is also approximately halved, each table entry requiring only 4 bytes instead of approximately 8 bytes for a series of 'compare immediate'/branch instructions (For larger input variables, the saving is even greater).
</p>
<pre> * ------------------ interpreter --------------------------------------------*
LM R14,R0,=A(4,CT1,N) Set R14=4, R15 --&gt; table, and R0 =no. of entries in table (N)
TRY CLC INPUT1,0(R15) ********* Found value in table entry&nbsp;?
BE ACTION * loop * YES, Load register pointer to sub-routine from table
AR R15,R14 * * NO, Point to next entry in CT1 by adding R14 (=4)
BCT R0,TRY ********* Back until count exhausted, then drop through
. default action ... none of the values in table match, do something else
LA R15,4(R15) point to default entry (beyond table end)
ACTION L R15,0(R15) get pointer into R15,from where R15 points
BALR R14,R15 Perform the sub-routine ("CALL" and return)
B END go terminate this program
* ------------------ control table -----------------------------------------*
* | this column of allowable EBCDIC or ASCII values is tested '=' against variable 'input1'
* | | this column is the 3-byte address of the appropriate subroutine
* v v
<b>CT1</b> DC C'A',AL3(ADD) START of Control Table (4 byte entry length)
DC C'S',AL3(SUBTRACT)
DC C'M',AL3(MULTIPLY)
DC C'D',AL3(DIVIDE)
N EQU (*-CT1)/4 number of valid entries in table (total length / entry length)
DC C'?',AL3(DEFAULT) default entry – used on drop through to catch all
INPUT1 DS C input variable is in this variable
* ------------------ sub-routines ------------------------------------------*
ADD CSECT sub-routine #1 (shown as separate CSECT here but might
. alternatively be in-line code)
. instruction(s) to add
BR R14 return
SUBTRACT CSECT sub-routine #2
. instruction(s) to subtract
BR R14 return
. etc..
</pre>
<p><b>improving the performance of the interpreter in above example </b>
</p>
<dl><dd>To make a selection in the example above, the average <a href="Instruction_path_length" title="Instruction path length">instruction path length</a> (excluding the subroutine code) is '4n/2 +3', but can easily be reduced, where n = 1 to 64, to a <a href="Linear_time" class="mw-redirect" title="Linear time">constant time</a> <span class="mwe-math-element mwe-math-element-inline"><span class="mwe-math-mathml-inline mwe-math-mathml-a11y" style="display: none;"><math xmlns="http://www.w3.org/1998/Math/MathML" alttext="{\displaystyle O(1)\,}">
<semantics>
<mrow class="MJX-TeXAtom-ORD">
<mstyle displaystyle="true" scriptlevel="0">
<mi>O</mi>
<mo stretchy="false">(</mo>
<mn>1</mn>
<mo stretchy="false">)</mo>
<mspace width="thinmathspace"></mspace>
</mstyle>
</mrow>
<annotation encoding="application/x-tex">{\displaystyle O(1)\,}</annotation>
</semantics>
</math></span><img src="./0fb3142d0d9658073a488c397897935724062694.svg" class="mwe-math-fallback-image-inline mw-invert skin-invert" aria-hidden="true" style="vertical-align: -0.838ex; width:5.132ex; height:2.843ex;" alt="{\displaystyle O(1)\,}" loading="lazy"></span> with a path length of '5' with <i>zero comparisons</i>, if a 256 byte translate table is first utilized to create a <i>direct</i> index to CT1 from the raw EBCDIC data. Where n = 6, this would then be equivalent to just 3 sequential compare &amp; branch instructions. However, where n&lt;=64, on average it would need approximately 13 <i>times</i> less instructions than using multiple compares. Where n=1 to 256, on average it would use approximately 42 <i>times</i> less instructions – since, in this case, one additional instruction would be required (to multiply the index by 4).</dd></dl>
<p><b>Improved interpreter</b> (up to <b>26 times less executed instructions</b> than the above example on average, where n= 1 to 64 and up to 13 times less than would be needed using multiple comparisons).
</p><p>To handle 64 different input values, approximately 85 lines of source code (or less) are required (mainly single line table entries) whereas multiple 'compare and branch' would require around 128 lines (the size of the <a href="Binary_file" title="Binary file">binary</a> is also almost halved – despite the additional 256 byte table required to extract the 2nd index).
</p>
<pre> * ------------------ interpreter --------------------------------------------*
SR R14,R14 ********* Set R14=0
CALC IC R14,INPUT1 * calc * put EBCDIC byte into lo order bits (24–31) of R14
IC R14,CT1X(R14) * * use EBCDIC value as index on table 'CT1X' to get new index
FOUND L R15,CT1(R14) ********* get pointer to subroutine using index (0,4, 8 etc.)
BALR R14,R15 Perform the sub-routine ("CALL" and return or Default)
B END go terminate this program
* --------------- additional translate table (EBCDIC --&gt; pointer table INDEX) 256 bytes----*
CT1X DC 12AL1(00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00) 12 identical sets of 16 bytes of x'00
* representing X'00 – x'BF'
DC AL1(00,<b>04</b>,00,00,<b>16</b>,00,00,00,00,00,00,00,00,00,00,00) ..x'C0' – X'CF'
DC AL1(00,00,00,00,<b>12</b>,00,00,00,00,00,00,00,00,00,00,00) ..x'D0' – X'DF'
DC AL1(00,00,<b>08</b>,00,00,00,00,00,00,00,00,00,00,00,00,00) ..x'E0' – X'EF'
DC AL1(00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00) ..x'F0' – X'FF'
* the assembler can be used to automatically calculate the index values and make the values more user friendly
* (for e.g. '04' could be replaced with the symbolic expression 'PADD-CT1' in table CT1X above)
* modified CT1 (added a default action when index = 00, single dimension, full 31 bit address)
<b>CT1</b> DC A(DEFAULT) index =00 START of Control Table (4 byte address constants)
PADD DC A(ADD) =04
PSUB DC A(SUBTRACT) =08
PMUL DC A(MULTIPLY) =12
PDIV DC A(DIVIDE) =16
* the rest of the code remains the same as first example
</pre>
<p><b>Further improved interpreter</b> (up to <b>21 times less executed instructions (where n&gt;=64)</b> than the first example on average and up to 42 <i>times</i> less than would be needed using multiple comparisons).
</p><p>To handle 256 different input values, approximately 280 lines of source code or less, would be required (mainly single line table entries), whereas multiple 'compare and branch' would require around 512 lines (the size of the <a href="Binary_file" title="Binary file">binary</a> is also almost halved once more).
</p>
<pre> * ------------------ interpreter --------------------------------------------*
SR R14,R14 ********* Set R14=0
CALC IC R14,INPUT1 * calc * put EBCDIC byte into lo order bits (24–31) of R14
IC R14,CT1X(R14) * * use EBCDIC value as index on table 'CT1X' to get new index
SLL R14,2 * * <b>multiply index by 4 (additional instruction)</b>
FOUND L R15,CT1(R14) ********* get pointer to subroutine using index (0,4, 8 etc.)
BALR R14,R15 Perform the sub-routine ("CALL" and return or Default)
B END go terminate this program
* --------------- additional translate table (EBCDIC --&gt; pointer table INDEX) 256 bytes----*
CT1X DC 12AL1(00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00) 12 identical sets of 16 bytes of x'00'
* representing X'00 – x'BF'
DC AL1(00,<b>01</b>,00,00,<b>04</b>,00,00,00,00,00,00,00,00,00,00,00) ..x'C0' – X'CF'
DC AL1(00,00,00,00,<b>03</b>,00,00,00,00,00,00,00,00,00,00,00) ..x'D0' – X'DF'
DC AL1(00,00,<b>02</b>,00,00,00,00,00,00,00,00,00,00,00,00,00) ..x'E0' – X'EF'
DC AL1(00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00) ..x'F0' – X'FF'
* the assembler can be used to automatically calculate the index values and make the values more user friendly
* (for e.g. '01' could be replaced with the symbolic expression 'PADD-CT1/4' in table CT1X above)
* modified CT1 (index now based on 0,1,2,3,4 not 0,4,8,12,16 to allow all 256 variations)
<b>CT1</b> DC A(DEFAULT) index =00 START of Control Table (4 byte address constants)
PADD DC A(ADD) =01
PSUB DC A(SUBTRACT) =02
PMUL DC A(MULTIPLY) =03
PDIV DC A(DIVIDE) =04
* the rest of the code remains the same as the 2nd example
</pre>
<div class="mw-heading mw-heading3"><h3 id="C_language">C language</h3></div>
<p>This example in <a href="C_(programming_language)" title="C (programming language)">C</a> uses two tables, the first (CT1) is a simple <a href="Linear_search" title="Linear search">linear search</a> one-dimensional lookup table – to obtain an index by matching the input (x), and the second, associated table (CT1p), is a table of addresses of labels to jump to.
</p>
<div style="font-size: 90%;" class="mw-highlight mw-highlight-lang-c mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">CT1</span><span class="p">[]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="s">"A"</span><span class="p">,</span><span class="w"> </span><span class="s">"S"</span><span class="p">,</span><span class="w"> </span><span class="s">"M"</span><span class="p">,</span><span class="w"> </span><span class="s">"D"</span><span class="w"> </span><span class="p">};</span><span class="w"> </span><span class="cm">/* permitted input values */</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">CT1p</span><span class="p">[]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Add</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Subtract</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Multiply</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Divide</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Default</span><span class="p">};</span><span class="w"> </span><span class="cm">/* labels to goto &amp; default*/</span>
<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="k">sizeof</span><span class="p">(</span><span class="n">CT1</span><span class="p">);</span><span class="w"> </span><span class="n">i</span><span class="o">++</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="cm">/* loop thru ASCII values */</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="o">==</span><span class="n">CT1</span><span class="p">[</span><span class="n">i</span><span class="p">])</span><span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="o">*</span><span class="n">CT1p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span><span class="w"> </span><span class="cm">/* found --&gt; appropriate label */</span>
<span class="w"> </span><span class="p">}</span>
<span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="o">*</span><span class="n">CT1p</span><span class="p">[</span><span class="n">i</span><span class="o">+</span><span class="mi">1</span><span class="p">];</span><span class="w"> </span><span class="cm">/* not found --&gt; default label */</span>
</pre></div>
<p>This can be made more efficient if a 256 byte table is used to translate the raw ASCII value (x) directly to a dense sequential index value for use in directly locating the branch address from CT1p (i.e. "<a href="Index_mapping" title="Index mapping">index mapping</a>" with a byte-wide array). It will then execute in <a href="Constant_time" class="mw-redirect" title="Constant time">constant time</a> for all possible values of x (If CT1p contained the names of functions instead of labels, the jump could be replaced with a dynamic function call, eliminating the switch-like goto – but decreasing performance by the additional cost of function <a href="Housekeeping_(computing)" title="Housekeeping (computing)">housekeeping</a>).
</p>
<div style="font-size: 80%;" class="mw-highlight mw-highlight-lang-c mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">CT1p</span><span class="p">[]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="o">&amp;&amp;</span><span class="n">Default</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Add</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Subtract</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Multiply</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="n">Divide</span><span class="p">};</span>
<span class="w"> </span><span class="cm">/* the 256 byte table, below, holds values (1,2,3,4), in corresponding ASCII positions (A,S,M,D), all others set to 0x00 */</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="n">CT1x</span><span class="p">[]</span><span class="o">=</span><span class="p">{</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x01'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x04'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x03'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x02'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x03'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span>
<span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">,</span><span class="w"> </span><span class="sc">'\x00'</span><span class="p">};</span>
<span class="w"> </span><span class="cm">/* the following code will execute in constant time, irrespective of the value of the input character (x) */</span>
<span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">CT1x</span><span class="p">(</span><span class="n">x</span><span class="p">);</span><span class="w"> </span><span class="cm">/* extract the correct subroutine index from table CT1x using its ASCII value as an index initially */</span>
<span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="o">*</span><span class="n">CT1p</span><span class="p">[</span><span class="n">i</span><span class="p">];</span><span class="w"> </span><span class="cm">/* goto (Switch to) the label corresponding to the index (0=default, 1=Add, 2=Subtract,.) - see CT1p */</span>
</pre></div>
<p>The next example below illustrates how a similar effect can be achieved in languages that do not support pointer definitions in data structures but do support indexed branching to a subroutine – contained within a (<a href="Zero-based_numbering" title="Zero-based numbering">0-based</a>) array of subroutine pointers. The table (CT2) is used to extract the index (from 2nd column) to the pointer array (CT2P). If pointer arrays are not supported, a SWITCH statement or equivalent can be used to alter the control flow to one of a sequence of program labels (e.g.: case0, case1, case2, case3, case4) which then either process the input directly, or else perform a call (with return) to the appropriate subroutine (default, Add, Subtract, Multiply or Divide,..) to deal with it.
</p>
<dl><dd><table class="wikitable">
<caption>CT2
</caption>
<tbody><tr>
<th>input 1</th>
<th><span class="monospaced">subr #</span>
</th></tr>
<tr>
<td><span class="monospaced">A</span></td>
<td><span class="monospaced">1</span>
</td></tr>
<tr>
<td><span class="monospaced">S</span></td>
<td><span class="monospaced">2</span>
</td></tr>
<tr>
<td><span class="monospaced">M</span></td>
<td><span class="monospaced">3</span>
</td></tr>
<tr>
<td><span class="monospaced">D</span></td>
<td><span class="monospaced">4</span>
</td></tr>
<tr>
<td><span class="monospaced">?</span></td>
<td><span class="monospaced">0</span>
</td></tr></tbody></table></dd></dl>
<p>As in above examples, it is possible to very efficiently translate the potential <a href="ASCII" title="ASCII">ASCII</a> input values (A,S,M,D or unknown) into a pointer array index without actually using a table lookup, but is shown here as a table for consistency with the first example.
</p>
<dl><dd><table class="wikitable">
<caption>CT2P<br><style data-mw-deduplicate="TemplateStyles:r886047488">
/* start https://en.wikipedia.org/ */


.mw-parser-output .nobold{font-weight:normal}


/* end https://en.wikipedia.org/ */
</style><span class="nobold">pointer array</span>
</caption>
<tbody><tr>
<th></th>
<th><a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> <a href="Array_data_structure" class="mw-redirect" title="Array data structure">array</a>
</th></tr>
<tr>
<td>→</td>
<td><span class="monospaced">default</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Add</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Subtract</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Multiply</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Divide</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">?other</span>
</td></tr></tbody></table></dd></dl>
<p>Multi-dimensional control tables can be constructed (i.e. customized) that can be 'more complex' than the above examples that might test for multiple conditions on multiple inputs or perform more than one 'action', based on some matching criteria. An 'action' can include a pointer to another subordinate control table. The simple example below has had an <i>implicit</i> 'OR' condition incorporated as an extra column (to handle lower case input, however in this instance, this could equally have been handled simply by having an extra entry for each of the lower case characters specifying the same subroutine identifier as the upper case characters). An extra column to count the actual run-time events for each input as they occur is also included.
</p>
<dl><dd><table class="wikitable">
<caption>CT3
</caption>
<tbody><tr>
<th>input 1</th>
<th>alternate</th>
<th><span class="monospaced">subr #</span></th>
<th><span class="monospaced">count</span>
</th></tr>
<tr>
<td><span class="monospaced">A</span></td>
<td><span class="monospaced">a</span></td>
<td><span class="monospaced">1</span></td>
<td><span class="monospaced">0</span>
</td></tr>
<tr>
<td><span class="monospaced">S</span></td>
<td><span class="monospaced">s</span></td>
<td><span class="monospaced">2</span></td>
<td><span class="monospaced">0</span>
</td></tr>
<tr>
<td><span class="monospaced">M</span></td>
<td><span class="monospaced">m</span></td>
<td><span class="monospaced">3</span></td>
<td><span class="monospaced">0</span>
</td></tr>
<tr>
<td><span class="monospaced">D</span></td>
<td><span class="monospaced">d</span></td>
<td><span class="monospaced">4</span></td>
<td><span class="monospaced">0</span>
</td></tr>
<tr>
<td><span class="monospaced">?</span></td>
<td><span class="monospaced">?</span></td>
<td><span class="monospaced">0</span></td>
<td><span class="monospaced">0</span>
</td></tr></tbody></table></dd></dl>
<p>The control table entries are then much more similar to conditional statements in <a href="Procedural_language" class="mw-redirect" title="Procedural language">procedural languages</a> but, crucially, without the actual (language dependent) conditional statements (i.e. instructions) being present (the generic code is <i>physically</i> in the interpreter that processes the table entries, not in the table itself – which simply embodies the program logic via its structure and values).
</p><p>In tables such as these, where a series of similar table entries defines the entire logic, a table entry number or pointer may effectively take the place of a <a href="Program_counter" title="Program counter">program counter</a> in more conventional programs and may be reset in an 'action', also specified in the table entry. The example below (CT4) shows how extending the earlier table, to include a 'next' entry (and/or including an 'alter flow' (<a href="Branch_(computer_science)" title="Branch (computer science)">jump</a>) subroutine) can create a <a href="Program_loop" class="mw-redirect" title="Program loop">loop</a> (This example is actually not the most efficient way to construct such a control table but, by demonstrating a gradual 'evolution' from the first examples above, shows how additional columns can be used to modify behaviour.) The fifth column demonstrates that more than one action can be initiated with a single table entry – in this case an action to be performed <i>after</i> the normal processing of each entry ('-' values mean 'no conditions' or 'no action').
</p><p><a href="Structured_programming" title="Structured programming">Structured programming</a> or <a href="Structured_programming" title="Structured programming">"Goto-less" code</a>, (incorporating the equivalent of '<a href="Do_while_loop" title="Do while loop">DO WHILE</a>' or '<a href="For_loop" title="For loop">for loop</a>' constructs), can also be accommodated with suitably designed and 'indented' control table structures.
</p>
<table>

<tbody><tr style="vertical-align: bottom;">
<td>
<table class="wikitable">
<caption>CT4<br><span class="nobold">(a complete 'program' to read input1 and process, repeating until 'E' encountered)</span>
</caption>
<tbody><tr>
<th>input 1</th>
<th>alternate</th>
<th>subr #</th>
<th>count</th>
<th>jump
</th></tr>
<tr>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—</td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—</td>
<td><span class="monospaced">5</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td><span class="monospaced">E</span></td>
<td><span class="monospaced">e</span></td>
<td><span class="monospaced">7</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td><span class="monospaced">A</span></td>
<td><span class="monospaced">a</span></td>
<td><span class="monospaced">1</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td><span class="monospaced">S</span></td>
<td><span class="monospaced">s</span></td>
<td><span class="monospaced">2</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td><span class="monospaced">M</span></td>
<td><span class="monospaced">m</span></td>
<td><span class="monospaced">3</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td><span class="monospaced">D</span></td>
<td><span class="monospaced">d</span></td>
<td><span class="monospaced">4</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td><span class="monospaced">?</span></td>
<td><span class="monospaced">?</span></td>
<td><span class="monospaced">0</span></td>
<td><span class="monospaced">0</span></td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—
</td></tr>
<tr>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—</td>
<td data-sort-value="" style="vertical-align:middle; text-align:center" class="table-na">—</td>
<td><span class="monospaced">6</span></td>
<td><span class="monospaced">0</span></td>
<td><span class="monospaced">1</span>
</td></tr></tbody></table>
</td>
<td>
<table class="wikitable">
<caption>CT4P <span class="nobold">pointer array</span>
</caption>
<tbody><tr>
<th></th>
<th><a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> <a href="Array_data_structure" class="mw-redirect" title="Array data structure">array</a>
</th></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Default</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Add</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Subtract</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Multiply</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Divide</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Read Input1</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">Alter flow</span>
</td></tr>
<tr>
<td>→</td>
<td><span class="monospaced">End</span>
</td></tr></tbody></table>
</td></tr></tbody></table>
<div class="mw-heading mw-heading3"><h3 id="Table-driven_rating">Table-driven rating</h3></div>
<p>In the specialist field of <a href="Telecommunications_rating" title="Telecommunications rating">telecommunications rating</a> (concerned with the determining the cost of a particular call),
<b>table-driven rating</b> techniques illustrate the use of control tables in applications where the rules may change frequently because of market forces. The tables that determine the charges may be changed at short notice by non-programmers in many cases.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p><p>If the algorithms are not pre-built into the interpreter (and therefore require additional runtime interpretation of an expression held in the table), it is known as "Rule-based Rating" rather than table-driven rating (and consequently consumes significantly more overhead).
</p>
<div class="mw-heading mw-heading3"><h3 id="Spreadsheets">Spreadsheets</h3></div>
<p>A <a href="Spreadsheet" title="Spreadsheet">spreadsheet</a> data sheet can be thought of as a two dimensional control table, with the non empty cells representing data to the underlying spreadsheet program (the interpreter). The cells containing formula are usually prefixed with an equals sign and simply designate a special type of data input that dictates the processing of other referenced cells – by altering the control flow within the interpreter. It is the externalization of formulae from the underlying interpreter that clearly identifies both spreadsheets, and the above cited "rule based rating" example as readily identifiable instances of the use of control tables by non programmers.
</p>
<div class="mw-heading mw-heading2"><h2 id="Programming_paradigm">Programming paradigm</h2></div>
<p>If the control tables technique could be said to belong to any particular <a href="Programming_paradigm" title="Programming paradigm">programming paradigm</a>, the closest analogy might be automata-based programming or <a href="Reflection_(computer_science)" class="mw-redirect" title="Reflection (computer science)">"reflective"</a> (a form of <a href="Metaprogramming" title="Metaprogramming">metaprogramming</a> – since the table entries could be said to 'modify' the behaviour of the interpreter). The interpreter itself however, and the subroutines, can be programmed using any one of the available paradigms or even a mixture. The table itself can be essentially a collection of "<a href="Raw_data" title="Raw data">raw data</a>" values that do not even need to be compiled and could be read in from an external source (except in specific, platform dependent, implementations using memory pointers directly for greater efficiency).
</p>
<div class="mw-heading mw-heading2"><h2 id="Analogy_to_bytecode_/_virtual_machine_instruction_set">Analogy to bytecode / virtual machine instruction set</h2></div>
<p>A multi-dimensional control table has some conceptual similarities to <a href="Bytecode" title="Bytecode">bytecode</a> operating on a <a href="Virtual_machine" title="Virtual machine">virtual machine</a>, in that a <a href="Platform_dependent" class="mw-redirect" title="Platform dependent">platform dependent</a> <a href="Interpreter_(computing)" title="Interpreter (computing)">"interpreter"</a> program is usually required to perform the actual execution (that is largely conditionally determined by the tables content). There are also some conceptual similarities to the recent <a href="Common_Intermediate_Language" title="Common Intermediate Language">Common Intermediate Language</a> (CIL) in the aim of creating a common intermediate 'instruction set' that is independent of platform (but unlike CIL, no pretensions to be used as a common resource for other languages). <a href="P-code_machine" title="P-code machine">P-code</a> can also be considered a similar but earlier implementation with origins as far back as 1966.
</p>
<div class="mw-heading mw-heading2"><h2 id="Instruction_fetch">Instruction fetch</h2></div>
<p>When a multi-dimensional control table is used to determine program flow, the normal "hardware" <a href="Program_counter" title="Program counter">program counter</a> function is effectively simulated with either a <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointer</a> to the first (or next) table entry or else an <a href="Array_index" class="mw-redirect" title="Array index">index</a> to it. "Fetching" the instruction involves decoding the <i>data</i> in that table entry – without necessarily copying all or some of the data within the entry first. Programming languages that are able to use <a href="Pointer_(computer_programming)" title="Pointer (computer programming)">pointers</a> have the dual advantage that less <a href="Computational_overhead" class="mw-redirect" title="Computational overhead">overhead</a> is involved, both in accessing the contents and also advancing the counter to point to the next table entry after execution. Calculating the next 'instruction' address (i.e. table entry) can even be performed as an optional additional action of every individual table entry allowing <a href="Program_loops" class="mw-redirect" title="Program loops">loops</a> and or <a href="Branch_(computer_science)" title="Branch (computer science)">jump</a> instructions at any stage.
</p>
<div class="mw-heading mw-heading2"><h2 id="Monitoring_control_table_execution">Monitoring control table execution</h2></div>
<p>The interpreter program can optionally save the program counter (and other relevant details depending upon instruction type) at each stage to record a full or partial trace of the actual program flow for <a href="Debugging" title="Debugging">debugging</a> purposes, <a href="Hot_spot_(computer_science)" class="mw-redirect" title="Hot spot (computer science)">hot spot</a> detection, <a href="Code_coverage" title="Code coverage">code coverage</a> analysis and <a href="Profiling_(computer_programming)" title="Profiling (computer programming)">performance analysis</a> (see examples CT3 &amp; CT4 above).
</p>
<div class="mw-heading mw-heading2"><h2 id="Advantages">Advantages</h2></div>
<ul><li>clarity – <a href="Table_(information)" title="Table (information)">information tables</a> are <a href="Ubiquitous_computing" title="Ubiquitous computing">ubiquitous</a> and mostly inherently <a href="Understanding" title="Understanding">understood</a> even by the <a href="General_public" class="mw-redirect" title="General public">general public</a> (especially <a href="Fault_diagnosis" class="mw-redirect" title="Fault diagnosis">fault diagnostic</a> tables in <a href="User_guide" title="User guide">product guides</a>)</li>
<li>portability – can be designed to be 100% language independent (and platform independent – except for the interpreter)</li>
<li>flexibility – ability to execute either <a href="Language_primitive" title="Language primitive">primitives</a> or <a href="Subroutine" class="mw-redirect" title="Subroutine">subroutines</a> transparently and be custom designed to suit the problem</li>
<li>compactness – table usually shows condition/action pairing side-by-side (without the usual platform/language implementation dependencies), often also resulting in
<ul><li><a href="Binary_file" title="Binary file">binary file</a> – reduced in size through less duplication of instructions</li>
<li><a href="Source_code" title="Source code">source</a> file – reduced in size through elimination of multiple conditional statements</li>
<li>improved program load (or download) speeds</li></ul></li>
<li>maintainability – tables often reduce the number of source lines needed to be maintained v. multiple compares</li>
<li>locality of reference – compact tables structures result in tables remaining in <a href="Cache_(computing)" title="Cache (computing)">cache</a></li>
<li>code re-use – the "interpreter" is usually reusable. Frequently it can be easily adapted to new programming tasks using precisely the same technique and can grow 'organically' becoming, in effect, a <a href="Standard_library" title="Standard library">standard library</a> of tried and tested <a href="Subroutines" class="mw-redirect" title="Subroutines">subroutines</a>, controlled by the table definitions.</li>
<li>efficiency – systemwide optimization possible. Any performance improvement to the interpreter usually improves <i>all</i> applications using it (see examples in 'CT1' above).</li>
<li>extensible – new 'instructions' can be added – simply by extending the interpreter</li>
<li>interpreter can be written like an application program</li></ul>
<p>Optionally:-
</p>
<ul><li>the interpreter can be <a href="Introspection" title="Introspection">introspective</a> and "self <a href="Optimization_(computer_science)" class="mw-redirect" title="Optimization (computer science)">optimize</a>" using runtime <a href="Software_metric" title="Software metric">metrics</a> collected within the table itself (see CT3 and CT4 – with entries that could be periodically sorted by descending count). The interpreter can also optionally choose the most efficient lookup technique dynamically from metrics gathered at run-time (e.g. size of array, range of values, sorted or unsorted)</li>
<li><a href="Dynamic_dispatch" title="Dynamic dispatch">dynamic dispatch</a> – common functions can be pre-loaded and less common functions fetched only on first encounter to reduce <a href="Memory" title="Memory">memory</a> usage. In-table <a href="Memoization" title="Memoization">memoization</a> can be employed to achieve this.</li>
<li>The interpreter can have debugging, trace and monitor features built-in – that can then be switched on or off at will according to test or 'live' mode</li>
<li>control tables can be built 'on-the-fly' (according to some user input or from parameters) and then executed by the interpreter (without building code literally).</li></ul>
<div class="mw-heading mw-heading2"><h2 id="Disadvantages">Disadvantages</h2></div>
<ul><li>training requirement – application programmers are not usually trained to produce generic solutions</li></ul>
<p>The following mainly apply to their use in multi-dimensional tables, not the one-dimensional tables discussed earlier.
</p>
<ul><li><a href="Computational_overhead" class="mw-redirect" title="Computational overhead">overhead</a> – some increase because of extra level of <a href="Indirection_(programming)" class="mw-redirect" title="Indirection (programming)">indirection</a> caused by virtual instructions having to be 'interpreted' (this however can usually be more than offset by a well designed generic interpreter taking full advantage of efficient direct translate, search and conditional testing techniques that may not otherwise have been utilized)</li>
<li>Complex <a href="Expression_(programming)" class="mw-redirect" title="Expression (programming)">expressions</a> cannot always be used <i>directly</i> in data table entries for comparison purposes</li></ul>
<dl><dd>(these 'intermediate values' can however be calculated beforehand instead within a subroutine and their values referred to in the conditional table entries. Alternatively, a subroutine can perform the complete complex conditional test (as an unconditional 'action') and, by setting a <a href="Truth_bit" class="mw-redirect" title="Truth bit">truth flag</a> as its result, it can then be tested in the next table entry. See <a href="Structured_program_theorem" title="Structured program theorem">Structured program theorem</a>)</dd></dl>
<div class="mw-heading mw-heading2"><h2 id="Quotations">Quotations</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1244412712">
/* start https://en.wikipedia.org/ */


.mw-parser-output .templatequote{overflow:hidden;margin:1em 0;padding:0 32px}.mw-parser-output .templatequotecite{line-height:1.5em;text-align:left;margin-top:0}@media(min-width:500px){.mw-parser-output .templatequotecite{padding-left:1.6em}}


/* end https://en.wikipedia.org/ */
</style><blockquote class="templatequote"><p>Multiway branching is an important programming technique which is all too often replaced by an inefficient sequence of if tests. <a href="Peter_Naur" title="Peter Naur">Peter Naur</a> recently wrote me that he considers the use of tables to control program flow as a basic idea of computer science that has been nearly forgotten; but he expects it will be ripe for rediscovery any day now. It is the key to efficiency in all the best compilers I have studied.</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— <a href="Donald_Knuth" title="Donald Knuth">Donald Knuth</a>, <i>Structured Programming with go to Statements</i></p></div>
<blockquote class="templatequote"><p>There is another way to look at a program written in interpretative language. It may be regarded as a series of subroutine calls, one after another. Such a program may in fact be expanded into a long sequence of calls on subroutines, and, conversely, such a sequence can usually be packed into a coded form that is readily interpreted. The advantage of interpretive techniques are the compactness of representation, the machine independence, and the increased diagnostic capability. An interpreter can often be written so that the amount of time spent in interpretation of the code itself and branching to the appropriate routine is negligible</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— <a href="Donald_Knuth" title="Donald Knuth">Donald Knuth</a>, <i>The Art of Computer Programming</i> Volume 1, 1997, page 202</p></div>
<blockquote class="templatequote"><p>The space required to represent a program can often be decreased by the use of interpreters in which common sequences of operations are represented compactly. A typical example is the use of a finite-state machine to encode a complex protocol or lexical format into a small table</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— <a href="Jon_Bentley_(computer_scientist)" title="Jon Bentley (computer scientist)">Jon Bentley</a>, <i>Writing Efficient Programs</i></p></div>
<blockquote class="templatequote"><p>Jump tables can be especially efficient if the range tests can be omitted. For example, if the control value is an enumerated type (or a character) then it can only contain a small fixed range of values and a range test is redundant provided the jump table is large enough to handle all possible values</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— David.A. SPULER, <i>Compiler Code Generation for Multiway Branch Statements as a Static Search Problem</i></p></div>
<blockquote class="templatequote"><p>Programs must be written for people to read, and only incidentally for machines to execute.</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— "Structure and Interpretation of Computer Programs", preface to the first edition, Abelson &amp; Sussman</p></div>
<blockquote class="templatequote"><p>Show me your flowchart and conceal your tables, and I shall continue to be mystified. Show me your tables, and I won't usually need your flowchart; it'll be obvious.</p></blockquote><div class="templatequotecite"><p style="display: inline; padding-left: 2.3em;">— "The Mythical Man-Month: Essays on Software Engineering", <a href="Fred_Brooks" title="Fred Brooks">Fred Brooks</a></p></div>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Database-centric_architecture" title="Database-centric architecture">Database-centric architecture</a>&nbsp;– Software architecture</li>
<li><a href="Data-driven_testing" title="Data-driven testing">Data-driven testing</a></li>
<li><a href="Keyword-driven_testing" title="Keyword-driven testing">Keyword-driven testing</a>&nbsp;– Software testing methodology</li>
<li><a href="Threaded_code" title="Threaded code">Threaded code</a>&nbsp;– Program whose source code consists entirely of calls to functions</li></ul>
<div class="mw-heading mw-heading2"><h2 id="Notes">Notes</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><i>Programs from decision tables</i>, Humby, E., 2007,Macdonald, 1973 ... Biggerstaff, Ted J. Englewood Cliffs, NJ&nbsp;: Prentice-Hall <style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>0-444-19569-6</bdi></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://web.archive.org/web/20160610160908/http://www.dkl.com/wp-content/uploads/2016/05/DataKinetics-Table-Driven-Design.pdf">"Archived copy"</a> <span class="cs1-format">(PDF)</span>. Archived from <a rel="nofollow" class="external text" href="http://www.dkl.com/wp-content/uploads/2016/05/DataKinetics-Table-Driven-Design.pdf">the original</a> <span class="cs1-format">(PDF)</span> on 10 June 2016<span class="reference-accessdate">. Retrieved <span class="nowrap">17 May</span> 2016</span>.</cite><span class="cs1-maint citation-comment"><code class="cs1-code">{{cite web}}</code>: CS1 maint: archived copy as title (link)</span></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external free" href="http://www.netrino.com/node/137">http://www.netrino.com/node/137</a></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text">Carl Wright, Service Level Corpo. (2002) <i><a rel="nofollow" class="external text" href="http://www.servicelevel.net/rating_matters/newsletters/issue12.htm">Program Code Based vs. Table-driven vs. Rule-Based Rating</a></i>, Rating Matters issue n. 12, 13 November 2002 <a href="ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&nbsp;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/1532-1886">1532-1886</a></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text">Brian E. Clauser, Melissa J. Margolis, Stephen G. Clyman, Linette P. Ross (1997) <i><a rel="nofollow" class="external text" href="https://www.jstor.org/stable/1435350">Development of Automated Scoring Algorithms for Complex Performance Assessments: A Comparison of Two Approaches</a></i> Journal of Educational Measurement, Vol. 34, No. 2 (Summer, 1997), pp. 141–161</span>
</li>
</ol></div></div>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<ul><li><a rel="nofollow" class="external text" href="http://www.methodsandtools.com/archive/archive.php?id=39">Decision Table Based Methodology </a></li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20090824073244/http://pplab.snu.ac.kr/courses/adv_pl05/papers/p261-knuth.pdf">Structured Programming with go to Statements</a> by <a href="Donald_Knuth" title="Donald Knuth">Donald Knuth</a></li>
<li><a rel="nofollow" class="external text" href="https://www.citeulike.org/user/derek_farn/article/2303550">Compiler code generation for multiway branch statements as a static search problem</a> 1I994, by David A. Spuler</li></ul>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="http://www.microsoft.com/technet/scriptcenter/resources/pstips/jan08/pstip0111.mspx">Switch statement in Windows PowerShell</a> describes extensions to standard switch statement (providing some similar features to control tables)</li>
<li><a rel="nofollow" class="external text" href="https://www.cs.auckland.ac.nz/~j-hamer/07.211/C/C-Lesson/C-LESSON.4">Control Table example in "C" language using pointers</a>, by Christopher Sawtell c1993, Department of Computer Science, <a href="University_of_Auckland" title="University of Auckland">University of Auckland</a></li>
<li><a rel="nofollow" class="external text" href="http://www.dkl.com/wp-content/uploads/2016/05/DataKinetics-Table-Driven-Design.pdf">Table driven design </a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20160610160908/http://www.dkl.com/wp-content/uploads/2016/05/DataKinetics-Table-Driven-Design.pdf">Archived</a> 10 June 2016 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a> by Wayne Cunneyworth of DataKinetics</li>
<li><a rel="nofollow" class="external text" href="http://commons.oreilly.com/wiki/index.php/From_Requirements_to_Tables_to_Code_and_Tests">From Requirements to Tables to Code and Tests</a> By George Brooke</li>
<li><a rel="nofollow" class="external text" href="http://portal.acm.org/citation.cfm?id=362041.362195&amp;coll=GUIDE&amp;dl=GUIDE&amp;CFID=60499203&amp;CFTOKEN=67618699">Some comments on the use of ambiguous decision tables and their conversion to computer programs</a> by P. J. H. King and R. G. Johnson, Univ. of London, London, UK</li>
<li><a rel="nofollow" class="external text" href="http://portal.acm.org/citation.cfm?id=364113&amp;dl=GUIDE&amp;coll=GUIDE&amp;CFID=60499203&amp;CFTOKEN=67618699">Ambiguity in limited entry decision tables</a> by P. J. H. King</li>
<li><a rel="nofollow" class="external text" href="http://portal.acm.org/citation.cfm?id=365896&amp;dl=GUIDE&amp;coll=GUIDE&amp;CFID=60499203&amp;CFTOKEN=67618699">Conversion of decision tables to computer programs by rule mask techniques</a> by P. J. H. King</li>
<li><a rel="nofollow" class="external text" href="https://ols.fedoraproject.org/GCC/Reprints-2008/sayle-reprint.pdf">A Superoptimizer Analysis of Multiway Branch Code Generation</a> <a rel="nofollow" class="external text" href="https://web.archive.org/web/20120227064827/http://ols.fedoraproject.org/GCC/Reprints-2008/sayle-reprint.pdf">Archived</a> 27 February 2012 at the <a href="Wayback_Machine" title="Wayback Machine">Wayback Machine</a> section 3.9, page 16 index mapping</li>
<li><a rel="nofollow" class="external text" href="http://www.netrino.com/node/137">Jump Tables via Function Pointer Arrays in C/C++</a> Jones, Nigel. "Arrays of Pointers to Functions <a rel="nofollow" class="external autonumber" href="http://www.rmbconsulting.us/Publications/PointerToFunction.pdf">[1]</a>" Embedded Systems Programming, May 1999.</li>
<li><a rel="nofollow" class="external text" href="https://web.archive.org/web/20121106140140/http://stats.grok.se/en/200912/control_table">Page view statistics for this article for December 2009</a></li></ul>
<p class="mw-empty-elt">
</p>
<ul><li><a rel="nofollow" class="external text" href="http://is.ifmo.ru/download/modelingsoftwarewithfinitestatemachinesapracticalapproach.pdf">Modelling software with finite state machines – a practical approach</a></li>
<li><a rel="nofollow" class="external text" href="https://docs.google.com/viewer?a=v&amp;q=cache:dytF6h4pD-4J:lss.fnal.gov/archive/tm/TM-1508.pdf+%22finite+state+table%22&amp;hl=en&amp;gl=uk&amp;pid=bl&amp;srcid=ADGEESgaFAmVjB_QzcxIn2MmK7N6QeffWYyHfUGTZG7zfB0DKoTaJUc2m_uncWXIteXNu_oCi570cGtCCjJeHYFUURZNoGdZMgn62OgTldHus4dTTN6BNt_vSce0jBoayojMcIGOfhcj&amp;sig=AHIEtbQ_1D3cO9a-FChv2QDKZqlzZ4oT4Q">Finite State Tables for General Computer Programming Applications January 1988</a> by Mark Leininger</li>
<li><a rel="nofollow" class="external text" href="http://msdn.microsoft.com/en-us/library/aa561913%28v=bts.20%29.aspx">MSDN:Trigger-Based Event Processing</a></li>
<li><a rel="nofollow" class="external text" href="http://c2.com/cgi/wiki?ControlTable">Control Table in c2.com</a></li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-08-07" href="https://en.wikipedia.org/wiki/?title=Control_table&amp;oldid=1304748101">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>